/**
 * 
 */
package com.wskj.library.user.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wskj.library.pojo.UserInfo;
import com.wskj.library.service.UserService;
import com.wskj.library.service.impl.UserServiceImpl;
import com.wskj.util.Page;
import com.wskj.util.StringUtil;

/**
 * @author 胡洋
 * @describe 
 * @Date 2018年3月22日下午6:09:59
 * @version 1.0
 */
@WebServlet(urlPatterns="/reader/list.do")
public class UserListServlet extends HttpServlet {	
	private  UserService userService=new UserServiceImpl();	
	
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		String name =  StringUtil.nullToString(req.getParameter("uname"));
		String deposite =  StringUtil.nullToString(req.getParameter("deposite"));
		String address  =  StringUtil.nullToString(req.getParameter("address"));
		String sex = StringUtil.nullToString(req.getParameter("sex"));
		int index=StringUtil.nullToInt(req.getParameter("pageIndex"));
		
		
		long counts=userService.getCountsByName(name,deposite,address,sex);
		
		Page<UserInfo> page=new Page<UserInfo>(index,10);
		page.setCounts(counts);
		
		List<UserInfo> users=userService.getUserWithPage(name,deposite,address,sex,index,page.getPageSize());
		
		page.setData(users);
		req.setAttribute("page", page);
		req.getRequestDispatcher("/WEB-INF/page/reader/list.jsp").forward(req, resp);
	}

}
